package com.learn;

import java.nio.channels.NonWritableChannelException;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


public class Cable implements Callable<String> {

    public String call() {
        System.out.println(Thread.currentThread().getName());
        int max=10000;
        int min=1000;
        Random random = new Random();
        int s = random.nextInt(max)%(max-min+1) + min;
        try {
            Thread.sleep(s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread() +":"+ s +"end");
        return Thread.currentThread().getName()+ s +"end";
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {

    }

    public static FutureTask<String> test(Callable mc) throws ExecutionException, InterruptedException {

        FutureTask<String> ft = new FutureTask<String>(mc);
        Thread thread = new Thread(ft);
        thread.start();
        return ft;
    }

}
